﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using System.Data;
namespace BAL
{
    public class BAL_TAIKHOAN
    {
        static QuanLyTiemNetDataContext db = new QuanLyTiemNetDataContext();
        //Đổi mật khẩu
        public static bool DoiMatKhau(string tenDN,string matKhauMoi)
        {
            db = new QuanLyTiemNetDataContext();
            bool thanhcong = false;
            try
            {
                TAIKHOAN tim = db.TAIKHOANs.Single(tk => tk.TenDangNhap.Equals(tenDN));
                if(tim!=null)
                {
                    tim.MatKhau = matKhauMoi;
                    db.SubmitChanges();
                    thanhcong = true;
                }
            }
            catch(Exception)
            {

            }
            return thanhcong;
        }
        //Lấy tài khoản
        public static DataTable LayTaiKhoan()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("TenDangNhap");
            dt.Columns.Add("MatKhau");
            var tk = from t in db.TAIKHOANs select t;
            foreach(var i in tk)
            {
                dt.Rows.Add(i.TenDangNhap, i.MatKhau);
            }
            return dt;

        }

    }
}
